#ifndef _network_Address_hpp_
#define _network_Address_hpp_

/** \file Address.hpp Types for network stuff
 *  \author Adrian Schweizer
 *  \created  $Sa 19 Jan 10:35:32 pm CET 2008 schwadri@SchwadriLaptop.local$
 *  \modified $So 20 Jan 03:38:39 pm CET 2008 schwadri@SchwadriLaptop.local$
 */

#include <string>

namespace network {


    /** \brief Encapsulates an Internet Address
    */
    class Address
    {
    public:
        typedef unsigned int            ip_type;
        typedef unsigned short          port_type;

        static const unsigned int   ANY;                 ///<
        static const unsigned int   NONE;                ///<

        Address()                                { }                     ///< Empty c'tor. Does not initialize anything
        /** \brief standard c'tor  */
        Address(unsigned int ip, unsigned short port)
        :   m_ip(ip),
            m_port(port)
        { }


        /** \name Accessors */ //@{
        unsigned int    Ip()    const               { return m_ip; }        ///< Get Ip
        unsigned short  Port()  const               { return m_port; }      ///< Get Port
        //@}

        /** \name Mutators */ //@{
        void            Ip(unsigned int ip)         { m_ip      =   ip; }   ///< Set Ip
        void            Port(unsigned short port)   { m_port    =   port; } ///< Set Port
        //@}
    private:
        ip_type         m_ip;
        port_type       m_port;
    };

    bool operator==(const Address& a1, const Address& a2);

    /** \brief Convert an Url string to an Ip
    */
    Address::ip_type    UrlToIp(const std::string& hostname);

    /** \brief Convert an Ip to an Url string
    */
    std::string         IpToUrl(Address::ip_type ip);

    /*TODO:*/
    //std::string         IpToString(Address::ip_type ip);

    /** \brief Retreive the local hosts Ip.
     *  This returns the Ip of the localhost. Which depending on whether or not the host is behind a NAT device
     *  may be a local or global Ip.
     */
    Address::ip_type    LocalHostIp();

    /** \brief Returns a string containing the localhost's name
    */
    std::string         LocalHostName();

} // namespace network

#endif // _network_Address_hpp_
